<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  class PowerfulMap extends Map {
    constructor(arg) {
      try {
        if (PowerfulMap.__type(arg)  === 'object') {
          super(Object.entries(arg))
        } else {
          super(arg)
        }
      } catch (error) {
        console.error(error)
      }
    }

    static __type (arg) {
      return Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
    }

    /**
     * 支持 map 方法
     *
     * @param callback 传入一个迭代器函数，迭代键值对
     * @returns {*[]} 以数组的形式返回每次迭代的值
     */
    map (callback) {
      const __map = []
      for (const [key, value] of this) {
        __map.push(callback(value, key))
      }
      return __map
    }

    /**
     * MAP 转 JSON
     *
     * @returns {{}} 以 JSON 的形式 返回
     */
    json () {
      const __json = {}
      for (const [key, value] of this) {
        __json[key] = value
      }
      return __json
    }
  }

  const so = new PowerfulMap ({ a: 'aaa', b: 'bbb', c: 'ccc'  })

  console.log(so, so.get('a'))
  const __return = so.map((value, key) => {
    console.log(value, key)
    return 'xxx'
  })
  console.log(__return)

  const objData = Object.entries({ a: 'aaa', b: 'bbb', c: 'ccc'  })
  const obj = new PowerfulMap(objData)
  console.log(obj, objData)
  console.log(obj.json())

</script>
</body>
</html>
